/**
 * Created by superman on 17/2/16.
 */

import axios from '../http'
import Qs from 'qs'
import jquery from 'jquery'
import vm from '../main'

let urls = {
    uploadAtt:'/api/attachment/upload',//上传附件
    proLogin:'/api/proprietor/login',//业主登录
    getSms:'/api/proprietor/getmsgcode',//获取短信验证码
    getCaptcha:'/api/proprietor/getcaptcha',//获取图片验证码
    checkCaptcha:'/api/proprietor/checkcaptcha',//检查图片验证码
    getHouseList:'/api/proprietor/estate/list',//获取房屋列表
    getHouseInfo:'/api/proprietor/houseinfo',//获取房屋信息
    getBulletinList:'/api/proprietor/bulletin/list',//获取公告信息
    getVoteList:'/api/proprietor/vote/list',//获取投票列表
    getBulletinTypes:'/api/proprietor/bulletin/gettypes',//获取公告类型列表
    getBulletinDetail:'/api/proprietor/bulletin/detail',//获取公告详情
    getVoteDetail:'/api/proprietor/vote/detail',//获取投票详情
    getVoteTypes:'/api/proprietor/vote/gettypes',//获取投票类型
    submitVote:'/api/proprietor/vote/savevalue',//提交投票结果
    getAdviceList:'/api/proprietor/suggestion/list',//建议列表
    getComplaintList:'/api/proprietor/complaint/list',//投诉列表
    getAdviceRefType:'/api/proprietor/suggestion/refType',//建议类型
    saveAdvice:'/api/proprietor/suggestion/save',//提交建议
    saveComplaint:'/api/proprietor/complaint/save',//保存投诉
    getComplaintTab:'/api/proprietor/complaint/complainttab/list',//投诉tab数据
    getAdviceDetail:'/api/proprietor/suggestion/detailsuggest',//建议详情
    getComplaintDetail:'/api/proprietor/complaint/detail',//建议详情
    adviceReply:'/api/proprietor/suggestion/addsuggestreply',//建议回复
    complaintReply:'/api/proprietor/complaint/addreply',//回复投诉
    getAdviceReplyList:'/api/proprietor/suggestion/detailsuggestreply',//建议回复列表
    getComplaintReplyList:'/api/proprietor/complaint/detailreply',//投诉回复列表
    getFacilityTypes:'/api/proprietor/facility/gettypes',//获取设备设施类型列表
    getFacilitySite:'/api/proprietor/facility/getsite',//设备设施位置
    getFacList:'/api/proprietor/facility/list',//获取设备设施列表
    getRepairList:'/api/proprietor/repair/list',//维修列表
    getMaintainList:'/api/proprietor/maintain/list',//保养列表
    getFacDetail:'/api/proprietor/facility/detail',//设备详情
    getRepairDetail:'/api/proprietor/repair/detail',//维修详情
    getMaintainDetail:'/api/proprietor/maintain/detail',//维护详情
}

//包装get
let getMethod = (url,query) => axios.get(url + '?' + Qs.stringify(query));

let postMethod = (url,query) => axios.post(url , query);//包装post

let ajaxupload = (url,query) => jquery.ajax({
    url:axios.defaults.baseURL+url,
    type:'POST',
    cache:false,
    data:query,
    processData : false,
    contentType : false
})

let get = (reqUrl,query) => getMethod(urls[reqUrl],query);

// let post = (reqUrl,query) => postMethod(urls[reqUrl],query);

let uploadAtt = (reqUrl,query) => ajaxupload(urls[reqUrl],query);

let post = async function(reqUrl,query){
    // if(reqUrl == 'login'){//登录api不需要检查token
    //     return postMethod(urls[reqUrl],query)
    // }else{
        let res = await postMethod(urls[reqUrl],query);
        console.log(res);
        if(!res){
            vm.$swal({title: "错误提示",text: '网络请求中断，请确认！', type:'error',  confirmButtonText: '确定' })
            return null;
        }
        // if(res.data.msg.val== '-2'){
        //     // alert('登录过期重新跳转..');
        //     // vm.$swal({title: "身份认证失效",text: "请重新登录 ！", timer: 2000,type:'error', showConfirmButton: false });
        //     // location.href = '/#/login'
        //     return null;
        // }else
        if(res.data.msg.val != '0'){
            vm.$swal({title: "错误提示",text: res.data.msg.str, type:'error',  confirmButtonText: '确定' })
            return null;
        }
        else{//返回正常数据
            return res;
        }
    // }
}

export default {
    get:get,
    post:post,
    url:axios.defaults.baseURL,
    uploadAtt:uploadAtt,
}




